//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Globals.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TKanaForm *KanaForm;
//---------------------------------------------------------------------------
__fastcall TKanaForm::TKanaForm(TComponent* Owner)
 : TForm(Owner)
{
}


//--------------------------------//
//                                //
//--------------------------------//
void __fastcall TKanaForm::ShowText( BYTE *String, int flag )
{
  WORD val[4];
  BYTE *TextBuf = String,
       *TEMP;
  char buf[256];
  bool cwFirst;
  static AnsiString buffer;

  //
  if ( flag ) kanaEdit->Clear( );
  buffer = "";
  //
//  if ( flag || txt.ptr_index == last_ptr_index ) return;
  if ( flag ) return;
  // We displayed it so display no more
  last_ptr_index = txt.ptr_index;
  kanaEdit->Clear( );
  //------------------------//
  //                        //
  //------------------------//
  kanaEdit->Lines->BeginUpdate( );

  txt.data = 0;
  while( txt.data != 0xFF )
  { //
    txt.data = TextBuf[0];
    TextBuf += 1;

    //----------------//
    // End Text Write //
    //----------------//
    if ( txt.data == 0xFF )
    {
      if ( flag == 2 ) return;
      break;
    }

    //-------------//
    // Line break  //
    //-------------//
    if ( txt.data == 0xFC )
    { //
      buffer = buffer + "\r\n";
      continue;
    }

    //-----------------//
    // Standard text   //
    //-----------------//
    if ( duals[ (txt.data << 8) + TextBuf[0] ].length )
    {
      buffer = buffer + AnsiString( (char *)duals[ (txt.data << 8) + TextBuf[0] ].text );
      TextBuf += 1;
    }
    else
    if ( codes[ txt.data ].length )
      buffer = buffer + AnsiString( (char *)codes[ txt.data ].text );
    else
      buffer = buffer + AnsiString( "[$" + IntToHex(txt.data, 2 ) + "]" );
   //
  } // WEND

  kanaEdit->Text = buffer;
  txt.data       = 0;
  kanaEdit->Lines->EndUpdate( );
}


//--------------------------------//
//                                //
//--------------------------------//
void __fastcall TKanaForm::FormCreate(TObject *Sender)
{
  last_ptr_index = -1;
}


